package com.cloud.logger.zchain.zchainserver.service;

import com.cloud.logger.zchain.core.common.base.ResultMessage;
import com.cloud.logger.zchain.core.common.constant.ResultCodeConstant;
import com.cloud.logger.zchain.zchainserver.entity.ZchainLoggerIgnore;
import com.cloud.logger.zchain.zchainserver.mongo.ZchainLoggerIgnoreRepository;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 浙江卓锐科技股份有限公司
 *
 * @author zhengyt
 * @create 2017/12/5
 * @description
 */
@Service
public class ZchainLoggerIgnoreService {

    @Resource
    private ZchainLoggerIgnoreRepository loggerIgnoreRepository;

    public ResultMessage findByCode(String code){
        ResultMessage resultMessage = new ResultMessage();
        List loggerIgnoreList = loggerIgnoreRepository.findByCode(code);
        resultMessage.setCode(ResultCodeConstant.SERVICE_SUCCESS_CODE);
        resultMessage.setContent(loggerIgnoreList);
        return resultMessage;
    }

    public ResultMessage saveLogIgnore(ZchainLoggerIgnore zchainLoggerIgnore){
        ResultMessage resultMessage = new ResultMessage();
        loggerIgnoreRepository.save(zchainLoggerIgnore);
        if(StringUtils.isBlank(zchainLoggerIgnore.getId())){
            resultMessage.setCode(ResultCodeConstant.SERVICE_SUCCESS_CODE);
            resultMessage.setIsSuccess(false);
            resultMessage.setMessage("保存失败!");
            return resultMessage;
        }
        resultMessage.setCode(ResultCodeConstant.SERVICE_SUCCESS_CODE);
        resultMessage.setMessage("保存成功!");
        return resultMessage;
    }

    public ResultMessage deleteLogIgnore(String id){
        ResultMessage resultMessage = new ResultMessage();
        loggerIgnoreRepository.delete(id);
        resultMessage.setCode(ResultCodeConstant.SERVICE_SUCCESS_CODE);
        return  resultMessage;
    }


}